<template>
	<view v-if="modelValue" class="el-loading" :class="mode == 'circle' ? 'el-loading-circle' : 'el-loading-flower'" :style="[cricleStyle]"></view>
</template>

<script setup>
	import { computed } from "vue";
	const props = defineProps({
		// 动画的类型
		mode: {
			type: String,
			default: 'circle'
		},
		// 动画的颜色
		color: {
			type: String,
			default: '#c7c7c7'
		},
		// 加载图标的大小，单位rpx
		size: {
			type: [String, Number],
			default: '34'
		},
		// 是否显示动画
		modelValue: {
			type: Boolean,
			default: true
		},
	});
	
	const emits = defineEmits(["modelValue","update:modelValue"]);
	
	const cricleStyle = computed(()=>{
		let style = {};
		style.width = props.size + 'rpx';
		style.height = props.size + 'rpx';
		if (props.mode == 'circle') style.borderColor = `#e4e4e4 #e4e4e4 #e4e4e4 ${props.color ? props.color : '#c7c7c7'}`;
		return style;
	});
</script>

<style lang="scss" scoped>
	.el-loading-circle {
		display: inline-flex;
		vertical-align: middle;
		width: 28rpx;
		height: 28rpx;
		background: 0 0;
		border-radius: 50%;
		border: 2px solid;
		border-color: #e5e5e5 #e5e5e5 #e5e5e5 #8f8d8e;
		animation: el-circle 1s linear infinite;
	}
	
	.el-loading-flower {
		width: 20px;
		height: 20px;
		display: inline-block;
		vertical-align: middle;
		animation: el-flower 1s steps(12) infinite;
		background: transparent url() no-repeat;
		background-size: 100%;
	}
	
	@keyframes el-flower {
		0% {
			transform: rotate(0deg);
		}
	
		to {
			transform: rotate(1turn);
		}
	}
	
	@keyframes el-circle {
		0% {
			transform: rotate(0);
		}
	
		100% {
			transform: rotate(360deg);
		}
	}
</style>